<?php
function callTencentAiApi($assistant_id, $token, $message) {
    $url = 'https://open.hunyuan.tencent.com/openapi/v1/agent/chat/completions';

    // 定义请求头
    $headers = [
        'X-Source: openapi',
        'Content-Type: application/json',
        "Authorization: Bearer $token"  // 使用传入的 token
    ];

    // 定义请求体
    $data = [
        "assistant_id" => $assistant_id,
        "user_id" => "儒释道",
        "stream" => false,
        "messages" => [
            [
                "role" => "user",
                "content" => [
                    [
                        "type" => "text",
                        "text" => $message // 示例文本，可以根据需要修改
                    ]
                ]
            ]
        ]
    ];

    // 将请求体转换为 JSON 格式的字符串
    $json_data = json_encode($data, JSON_UNESCAPED_UNICODE);

    $response = curlRequest($url, 'POST', $json_data, $headers);

    if ($response['success']) {
        return $response['response']; // 打印响应内容
    } else {
        return 'Error: ' . $response['error']; // 打印错误信息
    }
}


/*// 使用示例
$assistant_id = "I4aVQTHpsJro"; // 动态传入 assistant_id
$user_id = "username";           // 动态传入 user_id
$message = "能创建一个穿着古装的头像吗？"; // 动态传入的消息
$token = "<token>";              // 动态传入的 token

// 调用函数
$response = callTencentAiApi($assistant_id, $user_id, $message, $token);

// 打印响应
echo $response;*/

